package dietAndroidClient;

import com.mnk.TCPsoketTest.R;
import java.io.IOException;


import networking.TCPclient;

import org.apache.http.client.ClientProtocolException;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;

import com.android.facebookcon.C;
import com.android.facebookcon.FacebookConActivity.AuthorizeListener;
import com.facebook.android.DialogError;
import com.facebook.android.Facebook;
import com.facebook.android.Facebook.DialogListener;
import com.facebook.android.FacebookError;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.SeekBar;

public class RankActivity extends Activity implements OnClickListener{
	
	
	// Taejin Kim, 2011.10.12
	// Main, ADD, RANK 화占쏙옙 占싱듸옙 占쏙옙占쏙옙
	
	private String return_msg;
	private Button mainActivityButton;
	private Button calendarActivityButton;
	private Button addActivityButton;
	private Button settingActivityButton;
	private SeekBar seekBar1;
	private SeekBar seekBar2;
	private SeekBar seekBar3;
	private SeekBar seekBar4;
	private Facebook mFacebook = new Facebook(C.FACEBOOK_APP_ID);
	private Button  mBtnFeed; 
	private EditText mEtContent;
	
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.ranking);
    
    mainActivityButton = (Button) findViewById(R.id.button1);
    mainActivityButton.setOnClickListener(this);
    
    addActivityButton = (Button) findViewById(R.id.button5);
    addActivityButton.setOnClickListener(this);

    calendarActivityButton = (Button) findViewById(R.id.button2);
    calendarActivityButton.setOnClickListener(this);
    
    settingActivityButton = (Button) findViewById(R.id.button4);
    settingActivityButton.setOnClickListener(this);

    mEtContent = (EditText) findViewById(R.id.etContent);
    
    mBtnFeed = (Button) findViewById(R.id.Button01);
    mBtnFeed.setOnClickListener(this);
    // Call necessary values from DB
    
    
    // TEST SeekBar
    seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
    seekBar1.setProgress(50);
    
	TCPclient tp = new TCPclient("RANKING");
	
	tp.run();
    
  }
  
   @Override
	public void onClick(View v) {
		
		switch (v.getId()) {
		case R.id.button1:
			Intent main = new Intent(this, DietClient.class);
		    startActivity(main);
		    finish();
			break;
		case R.id.button5:
			Intent add = new Intent(this, AddActivity.class);
		    startActivity(add);
		    finish();
			break;
		case R.id.button2:
			Intent cal = new Intent(this, CalendarView.class);
			startActivity(cal);
			finish();
			break;
		case R.id.button4:
			Intent set = new Intent(this, SettingActivity.class);
			startActivity(set);
			finish();
			break;
		case R.id.Button01:  // Facebook占쏙옙 占쌜억옙占쏙옙
	        feed();
	        break;
	      
			
		}
	} 
   
   @Override
   public void onActivityResult(int requestCode, int resultCode, Intent data)
   {
     super.onActivityResult(requestCode, resultCode, data);
    //占쏙옙占싱쏙옙占쏙옙
     if (resultCode == RESULT_OK)
     {
       if (requestCode == C.FACEBOOK_AUTH_CODE)
       {
         mFacebook.authorizeCallback(requestCode, resultCode, data);
       }
     }
     else
     {
       if (requestCode == C.FACEBOOK_AUTH_CODE)
       {
         mFacebook.authorizeCallback(requestCode, resultCode, data);
       }      
     }
   }
  
   private void feed()
   {
 	  try
 	    {
 		  	mFacebook.authorize2(this, new String[] {"publish_stream, user_photos, email"}, 
 	    		new AuthorizeListener());
 		  
 		     Bundle params = new Bundle();
 		     params.putString("message", "Dieter by 8Team."/*mEtContent.getText().toString()+"媛��섏뀲�듬땲��"*/);
 		     params.putString("name", "8Team");
 		     params.putString("link", "");
 		     params.putString("description", "Posted by IT Project.");
 		     params.putString("picture", "");
 		     Log.d("facebook","11111111111");
 		      mFacebook.request("me/feed", params, "POST");
 		     Log.d("facebook","2222222222222");
 	    }
 	    catch (Exception e)
 	    {
 	      e.printStackTrace();
 	    }
  }
   
   private void logout()
   {
 	  try
 	    {
 	      mFacebook.logout(this);      
 	    }
 	    catch (Exception e)
 	    {
 	      e.printStackTrace();
 	    }
   }
   
   // Facebook 占쏙옙占쏙옙占쏙옙 처占쏙옙占쏙옙 占쏙옙占쏙옙 callback class
   public class AuthorizeListener implements DialogListener
   {
     @Override
     public void onCancel()
     {
       // TODO Auto-generated method stub
     }

     @Override
     public void onComplete(Bundle values)
     {
       // TODO Auto-generated method stub
       if (C.D) Log.v(C.LOG_TAG, "::: onComplete :::");
       if (C.D) Log.v(C.LOG_TAG2, "::: onComplete :::");
     }

     @Override
     public void onError(DialogError e)
     {
       // TODO Auto-generated method stub
     }

     @Override
     public void onFacebookError(FacebookError e)
     {
       // TODO Auto-generated method stub
     }
   }
}
